<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    okText="确定"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
      
        <!-- <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="所属开发区">
          <a-select placeholder="请选择所属开发区" v-decorator="['ParkTypeId', validatorRules.parktypeid]" >
            <a-select-option value="">请选择</a-select-option>
            <a-select-option :value="item.BaseInfoId" v-for="(item,index) in ParkTypeData">{{item.Value}}</a-select-option>
          </a-select>
        </a-form-item> -->
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="园区代码">
          <a-input placeholder="请输入园区代码" v-decorator="['IndustrialParkCode', validatorRules.parkcode]" />
        </a-form-item>
        <!-- <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="上级园区">
          <a-select placeholder="请选择上级园区" v-decorator="['UpParkId', {}]" >
            <a-select-option value="">请选择</a-select-option>
            <a-select-option :value="item.BaseHighteckParkId" v-for="(item,index) in ParkListData">{{item.ParkName}}</a-select-option>
          </a-select>
        </a-form-item> -->
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="园区名称">
          <a-input placeholder="请输入园区名称" v-decorator="['IndustrialParkName', validatorRules.parkname]" />
        </a-form-item>
		    <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="排序">
          <a-input placeholder="请输入排序" v-decorator="['OrderNum']" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "BaseHighteckparkModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        ParkListData:[],
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        basehighteckparkid:{rules: [{ required: true, message: '请输入园区ID!' }]},
        parktypeid:{rules: [{ required: true, message: '请选择所属开发区!' }]},
        parkcode:{rules: [{ required: true, message: '请输入园区代码!' }]},
        parkname:{rules: [{ required: true, message: '请输入园区名称!' }]},

        updatebyid:{rules: [{ required: true, message: '请输入最近更新人!' }]},
        ts:{rules: [{ required: true, message: '请输入最近更新日期!' }]},
        datastatus:{rules: [{ required: true, message: '请输入状态!' }]},
        },
        ParkTypeData:[],
        url: {
          add: "/baseIndustrialPark/add",
          edit: "/baseIndustrialPark/update",
          baseList:"/baseInfo/queryRows",
          list:'/baseIndustrialPark/queryRows'
        },
      }
    },
    created () {
      
      this.getBaseData();
    },
    methods: {
      getParkData(){
        this.$http.postAction(this.url.list,{pageNo:1,pageSize:1000}).then((res)=>{
          if(res.status == 1){
            this.ParkListData = res.data.rows;
            if(this.model.BaseHighteckParkId){

              this.ParkListData = this.ParkListData.filter((e)=>{
                return e.BaseHighteckParkId !== this.model.BaseHighteckParkId
              })
            }
          }
        })
      },
      getBaseData(){
        this.$http.postAction(this.url.baseList,{pageNo:1,pageSize:100,selectFields:[],conditions:[{
              "field":"TypeCode",
              "operator":"=",
              "value":'ParkType'
            }]}).then((res)=>{
          if(res.status == 1){
            this.ParkTypeData = res.data.rows;

          }
        })
        
      },
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.model.ParkTypeId = this.model.ParkType == 1?1:this.model.ParkType == 2?2:'';
        this.model.UpParkId = this.model.UpPark;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'IndustrialParkCode','IndustrialParkName','OrderNum'))
		      //时间格式化
          
            this.getParkData();
          
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.BaseIndustrialParkId){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            
            console.log(formData)
            this.$http.postAction(httpurl,formData,method).then((res)=>{
              if(res.status == 1){
                that.$message.success('提交成功');
                if(method == 'post'){
                  this.form.resetFields();
                  this.model = {};
                }else{
                  that.close();
                }
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              // that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>